//
//  LoginViewController.swift
//  HR
//
//  Created by zhenyu on 17/6/25.
//  Copyright © 2017年 allblue. All rights reserved.
//

import UIKit

class LoginViewController: ViewController {
  
  weak var phoneView: HRTextFieldView!
  weak var passwordView: HRTextFieldView!
  
  weak var forgetBtn: Button!
  weak var loginBtn: Button!
  
  weak var registerBtn: Button!
  
  // MARK: - LifeCycle
  override func viewDidLoad() {
    super.viewDidLoad()
    setViews()
    // Do any additional setup after loading the view.
  }
  
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
  
  // MARK: - SetViews
  func setViews() {
    title = "登录"
    
    let logo = UIImageView(image: #imageLiteral(resourceName: "logo")).then { (i) in
      view.addSubview(i)
    }.then { (i) in
      i.snp.makeConstraints({ (make) in
        make.centerX.equalTo(view)
        make.top.equalTo(30)
        make.height.width.equalTo(78)
      })
    }
    
    
    phoneView = HRTextFieldView(type: .normal).then({ (v) in
      view.addSubview(v)
      v.placeHolder = "请输入手机号码"
    }).then({ (v) in
      v.snp.makeConstraints({ (make) in
        make.top.equalTo(logo.snp.bottom).offset(30)
        make.left.equalTo(view.snp.left).offset(15)
        make.right.equalTo(view.snp.right).offset(-15)
        make.height.equalTo(55)
      })
    })

    passwordView = HRTextFieldView(type: .eyes).then({ (v) in
      view.addSubview(v)
      v.placeHolder = "请输入密码"
    }).then({ (v) in
      v.snp.makeConstraints({ (make) in
        make.top.equalTo(phoneView.snp.bottom)
        make.left.right.equalTo(phoneView)
        make.height.equalTo(55)
      })
    })
    
    forgetBtn = Button().then({ (b) in
      view.addSubview(b)
      b.hlight()
      b.backgroundColor = UIColor.clear
      b.textColor = Color.lightFont
      b.title = "忘记密码?"
      b.fonts = HRFont(size: 13)
      b.addTarget(self, action: #selector(forgetAction), for: .touchUpInside)
    }).then({ (b) in
      b.snp.makeConstraints({ (b) in
        b.top.equalTo(passwordView.snp.bottom)
        b.right.equalTo(passwordView)
        b.width.equalTo(80)
        b.height.equalTo(40)
      })
    })
    
    loginBtn = Button().then({ (b) in
      view.addSubview(b)
      b.title = "登录"
      b.normal()
      b.addTarget(self, action: #selector(loginAction), for: .touchUpInside)
    }).then({ (b) in
      b.snp.makeConstraints({ (make) in
        make.top.equalTo(forgetBtn.snp.bottom).offset(30)
        make.left.right.equalTo(passwordView)
        make.height.equalTo(44)
      })
    })
    
    registerBtn = Button().then({ (b) in
      view.addSubview(b)
      b.hlight()
      b.backgroundColor = UIColor.clear
      b.textColor = Color.theme
      b.title = "立即注册"
      b.fonts = HRFont(size: 14)
      b.addTarget(self, action: #selector(registerAction), for: .touchUpInside)
    }).then({ (b) in
      b.snp.makeConstraints({ (b) in
        b.top.equalTo(loginBtn.snp.bottom).offset(10)
        b.centerX.equalTo(loginBtn)
        b.width.equalTo(80)
        b.height.equalTo(40)
      })
    })
  }
}



// MARK: - Actions
extension LoginViewController {
  func forgetAction() {
    let vc = ForgetOneViewController()
    Transition.push(vc: vc)
  }
  
  func loginAction() {
  
  }
  
  func registerAction() {
    let vc = RegisterViewController()
    Transition.push(vc: vc)
  }
}

